package com.ate.lib_core.http.product

import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory
import retrofit2.converter.gson.GsonConverterFactory

/**
 * @author Ate
 * @description:
 * @date :2020/12/9 10:59
 */
class HttpRetrofitUploadImpl :IRetrofitProduct {
    var mRetrofit: Retrofit? = null
    override fun create() {
        mRetrofit = Retrofit.Builder()
            .baseUrl("")
            .client(
                OkHttpClient.Builder()
                    .addInterceptor(HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY))
                    .build()
            )
            .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
            .addConverterFactory(GsonConverterFactory.create())
            .build()
    }

    override fun getRetrofit(): Retrofit? {
        if (mRetrofit == null) {
            create()
        }
        return mRetrofit
    }
}